namespace VfAnswersMe
{
    using System;
    using System.Linq;
    using Rsdn.Janus;
    using Rsdn.Janus.CoreServices.Extensibility;
    using Rsdn.Janus.CoreServices.ObjectModel;
    using Rsdn.Janus.DataModel;

    internal class AnswersMeMessage : VirtualForumMessage
    {
        public AnswersMeMessage(IServiceProvider provider)
            : base(provider)
        {
        }

        protected override void FillChildren()
        {
            // do nothing    
        }


        protected override IQueryable<IForumMessage> GetMessages(IJanusDataContext db)
        {
            // don't move to class member we need actual value
            int selfId = SharedInfo.GetIntValue(SharedInfoKeys.SelfId) ?? 0;

            return db.Messages(m => m.ParentID != 0 && m.Parent.UserID == selfId);
            #region SQL
            //--  SQLite
            //-- DECLARE @selfId Int32

            //-- SET @selfId = 95947

            //SELECT
            //    [m].[mid] as [ID],
            //    [m].[tid] as [TopicID],
            //    [m].[pid] as [ParentID],
            //    [m].[gid] as [ForumID],
            //    [m].[Subject],
            //    [m].[dte] as [Date1],
            //    [m].[uid] as [UserID],
            //    [m].[uclass] as [UserClass],
            //    [m].[UserNick],
            //    [m].[Name],
            //    [m].[article_id] as [ArticleId],
            //    [m].[LastModerated],
            //    [m].[Closed],
            //    [m].[Message],
            //    [m].[IsMarked],
            //    [m].[IsRead],
            //    [m].[ReadReplies]
            //FROM
            //    [messages] [m]
            //        LEFT JOIN [messages] [t1] ON [m].[pid] = [t1].[mid]
            //WHERE
            //    [m].[pid] <> 0 AND [t1].[uid] = @selfId

            #endregion
        }

        protected override bool IsLoadAllMessages
        {
            get { return false; }
        }
    }
}